<?php

class calendar {
	
	function calendar() {
		
		$out  = '<script type="text/javascript" language="Javascript">';
		$out .= "<!--\n";
		$out .= "var now = new Date();\n";
		$out .= "var cal = new CalendarPopup('calendar_div');\n";
		$out .= "cal.setCssPrefix(\"CAL\");";
		$out .= "cal.showNavigationDropdowns();\n";
		$out .= "cal.showYearNavigation();\n";
		
		if (isset($GLOBALS['Lang'])) {
			$months = explode (",", $GLOBALS['Lang']->get('_system.months'));
			@ array_walk($months, 'addslashes');
			$days   = explode (",", $GLOBALS['Lang']->get('_system.days'));
			foreach ($days as $d)
				$day_headers[] = strtoupper(substr($d, 0, 1));
			$today  = addslashes($GLOBALS['Lang']->get('_system.today'));
			
			$out .= "cal.setMonthNames('". implode("','", $months) ."');\n";
			$out .= "cal.setDayHeaders('". implode("','", $day_headers) ."');\n";
			$out .= "cal.setWeekStartDay(". $GLOBALS['Lang']->get('_system.weekstartday') .");\n";
			$out .= "cal.setTodayText('". $today ."');\n";
		} else {
			$out .= "cal.setMonthNames('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre');\n";
			$out .= "cal.setDayHeaders('L','M','M','G','V','S','D');\n";
			$out .= "cal.setWeekStartDay(1);\n";
			$out .= "cal.setTodayText('Oggi');\n";
		}
		
		$out .= "-->\n";
		$out .= "</script>\n";
		
		$GLOBALS['Template']->set('includes', $out);
	}
	
	function insert($fld_id, $img = '../modules/calendar/calendar.gif', $img_h = 16, $img_w = 16) {
		$id = uniqid('cal_');
		$out  = '<img src="'. $img .'" width="'. $img_w .'" height="'. $img_h .'" name="'. $id .'" id="'. $id .'" ';
		$out .= ' onclick="openCalendar(this, \'yyyy-MM-dd\');" alt="Apri calendario" />';
		return $out;
	}
	
}

?>